// Package controllers
// @Title  base.go
// @Description  基类控制器
// @Author  小斌 (时间 格式是2021/12/02  11:40)
// @Update  小斌 (时间 格式是2021/12/02  11:40)

package controllers

import (
	"beego-admin/models"
	"beego-admin/service"
	"github.com/astaxie/beego"
)

type BaseController struct {
	beego.Controller
	controllerName string
	actionName     string
	catId          int
}

type ReturnJson struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type ReturnLayuiJson struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Total int 		 `json:"count"`
	Data interface{} `json:"data"`
}

func (this *BaseController) Prepare() {
	controllerName,actionName := this.GetControllerAndAction()
	this.Data["controller_name"] = controllerName
	this.Data["action_name"] = actionName

	//查询文章目录
	articleCatList,_ := models.GetUseArticleCatList()
	this.Data["article_cat_list"] = articleCatList

	//查询站长推荐
	queryParams := models.ArticleQueryParams{
		PageSize: 6,
		Page:  1,
		BloggerRecommend:2,
	}

	articleList,_,_ := models.GetArticleList(queryParams)
	articleData := service.ArticleListFormat(articleList)
	this.Data["blogger_recommend_list"] = articleData

	this.catId,_ = this.GetInt("cat_id",0)
	this.Data["cat_id"] = this.catId
}

func (this *BaseController) AjaxReturn(code int, msg string, data interface{}) *ReturnJson {
	return &ReturnJson{Code: code, Msg: msg, Data: data}
}

func (this *BaseController) AjaxLayuiTableReturn(code int, msg string,total int, data interface{}) *ReturnLayuiJson {
	return &ReturnLayuiJson{Code: code, Msg: msg,Total: total, Data: data}
}

